﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HYI.SDBSERVER;
using eHCBaseClass;
using Sunny.UI;

namespace SHRSYSTEM
{
    public partial class FMI_USEWARRING : SDBSERVER.FMSINGLE
    {
        //入口函数
        public static Int32 StartMe(string sMainPara, string sPara, string sUser, DBSERVER sDB)
        {
            StaticClass.Selectm_MainPara = sMainPara;
            StaticClass.SelectItemValue = sPara;
            StaticClass.SelectUser = sUser;
            StaticClass.myDB = sDB;
            return 0;
        }

        private int iGridView = 0;
        private string sType = "V";
        private string sSite_No = string.Empty;
        //DBSERVER myADO = new DBSERVER();
        DBCache myCache = new DBCache();

        public FMI_USEWARRING()
        {
            InitializeComponent();
        }

        //查询代码
        protected override void OnSys04()
        {
            string sDate1 = uiDate1.Text;
            string sDate2 = uiDate2.Text;
            string SQL = "select a.flogindate,d.fpoint_name,c.fequipmenttag,b.username,a.fnote"
              +"  from i_tc_usewarring a,am_sys_user b, i_ts_box c,a_ts_point d"
              + "  where 1 = 1"
              + "  and a.user_id = b.id"
              + "  and c.fequipmentbarcode = a.fequipmentbarcode"
              + "  and c.fpoint_no = d.fpoint_no"
              + "  and convert(varchar(10),a.flogindate,120) between '" + sDate1 + "'"
              + "  and '" + sDate2 + "'";
            DataRowView dr2 = (DataRowView)cbfpoint_no.SelectedItem;
            if ((dr2 != null) && (cbfpoint_no.SelectedIndex > 0))
            {
                SQL = SQL + " and c.fpoint_no='" + dr2.Row["fpoint_no"].ToString() + "'";
            }

            DataRowView dr3 = (DataRowView)cbftakeuser.SelectedItem;
            if ((dr3 != null) && (cbftakeuser.SelectedIndex > 0))
            {
                SQL = SQL + " and a.user_id='" + dr3.Row["id"].ToString() + "'";
            }

            SQL = SQL + "  order by a.flogindate desc";
            Qrytable = StaticClass.myDB.query(SQL);

            base.OnSys04();
            rowindex = -1;

        }

        private void FMI_USEWARRING_Load(object sender, EventArgs e)
        {
            sUser = StaticClass.SelectUser;
            string[] strArray = StaticClass.Selectm_MainPara.Split(new char[] { ';' });
            sMenu = strArray[1];
            sSite_No = strArray[0];

            //按钮控制
            sys01.Visible = false; sys01.Tag = "1";
            sys02.Visible = false; sys02.Tag = "1";
            sys03.Visible = false; sys03.Tag = "1";
            sys05.Visible = false; sys05.Tag = "1";
            sys07.Visible = false; sys07.Tag = "1";
            sys08.Visible = false; sys08.Tag = "1";
            sys09.Visible = false; sys09.Tag = "1";
            sys10.Visible = false; sys10.Tag = "1";
            sys11.Visible = false; sys11.Tag = "1";

            uiDate1.Text = DateTime.Now.ToString("yyyy-MM-dd");
            uiDate2.Text = DateTime.Now.ToString("yyyy-MM-dd");

            //下拉框
            DataTable myUser = myCache.doGetDict("AM_SYS_USER", "");

            DataRow dr2 = myUser.NewRow();
            dr2["username"] = "请选择";
            dr2["id"] = "0";
            myUser.Rows.InsertAt(dr2, 0);
            cbftakeuser.DataSource = myUser;
            cbftakeuser.DisplayMember = "username";
            cbftakeuser.ValueMember = "id";
            cbftakeuser.SelectedIndex = 0;

            DataTable myStock = myCache.doGetDict("A_TS_POINT", "fpoint_flag=0");

            DataRow dr3 = myStock.NewRow();
            dr3["fpoint_name"] = "请选择";
            dr3["fpoint_no"] = "0";
            myStock.Rows.InsertAt(dr3, 0);
            cbfpoint_no.DataSource = myStock;
            cbfpoint_no.DisplayMember = "fpoint_name";
            cbfpoint_no.ValueMember = "fpoint_no";
            cbfpoint_no.SelectedIndex = 0;

            //执行查询代码
            OnSys04();

            //表格列显示统一控制
            if (iGridView == 0)
            {
                myCache.doSetGridVIew(sMenu, sUser, uiDGView);
                iGridView = iGridView + 1;
            }
        }

        private void cbfpoint_no_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        private void cbftakeuser_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }
    }
}
